package com.tarena.lbs.user.rpc;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.user.api.UserApi;
import com.tarena.lbs.user.api.pojo.dto.AdminDto;
import com.tarena.lbs.user.dao.mapper.UserMapper;
import com.tarena.lbs.user.dao.mapper.UserTagsMapper;
import com.tarena.lbs.user.service.impl.AdminServiceImpl;
import com.tarena.lbs.user.service.impl.UserGroupServiceImpl;
import com.tarena.lbs.user.service.impl.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
@Slf4j
@DubboService
public  class UserApiImpl implements UserApi {

    @Autowired
    private AdminServiceImpl adminService;
    @Autowired
    private UserTagsMapper userTagsMapper;
    @Autowired
    private UserServiceImpl userServiceImpl;
    @Autowired
    private UserGroupServiceImpl userGroupServiceImpl;

    @Override
    public List<Integer> getUserGroupIds(Integer userId, Integer businessId) {
        log.debug("获取用户所有分组id方法入参:userId={},businessId={}",userId,businessId);
        //通过用户id查询用户所有标签id
        List<Integer> tagIds = userServiceImpl.getTagIdsByUserId(userId);
        log.debug("用户所有标签id:{}",tagIds);
        if (tagIds == null || tagIds.size() == 0) {
            return Collections.emptyList();
        }
        List<Integer> groupIds = userGroupServiceImpl.getGroupIds(tagIds,businessId);
        return groupIds;
    }

    @Override
    public AdminDto getAdminById(Integer adminId) {
        return adminService.detail(adminId);
    }
}
